<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using <xsl:value-of select="Schema/@BusinessNameSpace" />;
using <xsl:value-of select="Schema/@EntityNameSpace" />;

namespace <xsl:value-of select="Schema/@NameSpace" />
{
	/// <summary>
	/// <xsl:value-of select="Schema/@TableName" />编辑
	/// </summary>
	public class <xsl:value-of select="Schema/@TableName" />Edit : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnOK;
		protected System.Web.UI.WebControls.Label lblMessage;
		<xsl:for-each select="Schema/Columns">
		protected System.Web.UI.WebControls.TextBox txt<xsl:value-of select="COLUMN_NAME" />;
		</xsl:for-each>

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				string strAction = Request.QueryString["action"];
				// 自动编号
				<xsl:for-each select="Schema/Columns[IS_IDENTITY='1']">
				txt<xsl:value-of select="COLUMN_NAME" />.ReadOnly = true;
				txt<xsl:value-of select="COLUMN_NAME" />.Text = "自动增长";
				</xsl:for-each>
				ViewState["Action"] = strAction;
				if(strAction == "edit")
				{
					<xsl:for-each select="Schema/Columns[IS_PK='1']">
					<xsl:if test="LANGUAGE_TYPE='System.String'">
						<xsl:value-of select="concat(LANGUAGE_TYPE,' ',COLUMN_NAME)" /> = Request.QueryString["<xsl:value-of select="COLUMN_NAME" />"];</xsl:if>
					<xsl:if test="LANGUAGE_TYPE!='System.String'">
						<xsl:value-of select="concat(LANGUAGE_TYPE,' ',COLUMN_NAME)" /> = <xsl:value-of select="LANGUAGE_TYPE" />.Parse(Request.QueryString["<xsl:value-of select="COLUMN_NAME" />"]);</xsl:if>
					</xsl:for-each>
					<xsl:value-of select="Schema/@TableName" /> obj<xsl:value-of select="Schema/@TableName" /> = <xsl:value-of select="Schema/@TableName" />Biz.Get<xsl:value-of select="Schema/@TableName" />(<xsl:for-each select="Schema/Columns[IS_PK='1']"><xsl:value-of select="COLUMN_NAME" /><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>);
					<xsl:for-each select="Schema/Columns">
					txt<xsl:value-of select="COLUMN_NAME" />.Text = obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="COLUMN_NAME" /><xsl:if test="LANGUAGE_TYPE!='System.String'">.ToString()</xsl:if>;</xsl:for-each>
					<xsl:for-each select="Schema/Columns[IS_PK='1']">
					txt<xsl:value-of select="COLUMN_NAME" />.ReadOnly = true;
					</xsl:for-each>
				}
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}

		private void InitializeComponent()
		{    
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				if((string)ViewState["Action"] == "add")
				{
					<xsl:value-of select="Schema/@TableName" /> obj<xsl:value-of select="Schema/@TableName" /> = new <xsl:value-of select="Schema/@TableName" />();
					<xsl:for-each select="Schema/Columns[IS_IDENTITY='0']">
					<xsl:if test="LANGUAGE_TYPE!='System.String'">
					obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="COLUMN_NAME" /> = <xsl:value-of select="LANGUAGE_TYPE" />.Parse(txt<xsl:value-of select="COLUMN_NAME" />.Text);</xsl:if>
					<xsl:if test="LANGUAGE_TYPE='System.String'">
					obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="COLUMN_NAME" /> = txt<xsl:value-of select="COLUMN_NAME" />.Text;</xsl:if>
					</xsl:for-each>
					<xsl:value-of select="Schema/@TableName" />Biz.Add<xsl:value-of select="Schema/@TableName" />(obj<xsl:value-of select="Schema/@TableName" />);
					ViewState["Action"] = "edit";
					<xsl:for-each select="Schema/Columns[IS_PK='1']">
					txt<xsl:value-of select="COLUMN_NAME" />.ReadOnly = true;
					</xsl:for-each>
					<xsl:for-each select="Schema/Columns[IS_IDENTITY='1']">
					txt<xsl:value-of select="COLUMN_NAME" />.ReadOnly = true;
					txt<xsl:value-of select="COLUMN_NAME" />.Text = obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="COLUMN_NAME" />.ToString();
					</xsl:for-each>
				}
				else if((string)ViewState["Action"] == "edit")
				{
					<xsl:value-of select="Schema/@TableName" /> obj<xsl:value-of select="Schema/@TableName" /> = <xsl:value-of select="Schema/@TableName" />Biz.Get<xsl:value-of select="Schema/@TableName" />(<xsl:for-each select="Schema/Columns[IS_PK='1']"><xsl:if test="LANGUAGE_TYPE!='System.String'"><xsl:value-of select="LANGUAGE_TYPE" />.Parse</xsl:if>(txt<xsl:value-of select="COLUMN_NAME" />.Text)<xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>);
					<xsl:for-each select="Schema/Columns">
					<xsl:if test="LANGUAGE_TYPE!='System.String'">
					obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="COLUMN_NAME" /> = <xsl:value-of select="LANGUAGE_TYPE" />.Parse(txt<xsl:value-of select="COLUMN_NAME" />.Text);
					</xsl:if>
					<xsl:if test="LANGUAGE_TYPE='System.String'">
					obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="COLUMN_NAME" /> = txt<xsl:value-of select="COLUMN_NAME" />.Text;
					</xsl:if>
					</xsl:for-each>
					<xsl:value-of select="Schema/@TableName" />Biz.Update<xsl:value-of select="Schema/@TableName" />(obj<xsl:value-of select="Schema/@TableName" />);
				}
				lblMessage.Text = "保存成功！";
			}
			catch(Exception ex)
			{
				lblMessage.Text = ex.Message;
			}
		}
	}
}</xsl:template>
</xsl:stylesheet>